//
//  WKChangeMailboxViewController.m
//  ourToken
//
//  Created by wakeup on 2018/6/4.
//  Copyright © 2018年 ourtoken. All rights reserved.
//

#import "WKChangeMailboxViewController.h"
#import "WKBaseHeader.h"

@interface WKChangeMailboxViewController ()

@property (weak, nonatomic) IBOutlet UIButton *sendCodeBtn;//发送验证码按钮
@property (weak, nonatomic) IBOutlet UIButton *sureBtn;//确定按钮

@property (nonatomic,strong) NSTimer *codeTimer;//验证码总时间
@property (nonatomic,assign) int timeCount;//获取验证吗可变的数字

@end

@implementation WKChangeMailboxViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNavigationView];
    [self layoutUI];
    self.view.backgroundColor = AppManager.tableBackColor;
}

- (void)setNavigationView {
    [super setNavigationView];
    self.navigationView.topTitleLabel.text = @"更换手机号";
}

- (void)layoutUI {
    [self.sendCodeBtn setTitleColor:AppManager.themeColor forState:UIControlStateNormal];
    
    self.sureBtn.backgroundColor = AppManager.themeColor;
    self.sureBtn.titleLabel.font = AppManager.btnFont;
    self.sureBtn.layer.cornerRadius = 5;
    self.sureBtn.layer.masksToBounds = YES;
}

- (IBAction)clickSendCodeBtn:(id)sender {
    self.sendCodeBtn.enabled = NO;
    self.timeCount = 60;
    self.codeTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(countDownTimeOnButton) userInfo:nil repeats:YES];
}

#pragma mark - 点击获取验证码后,60秒倒计时
-(void)countDownTimeOnButton{
    
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.sendCodeBtn setTitle:[NSString stringWithFormat:@"%d s",self.timeCount - 1] forState:UIControlStateNormal];
        self.timeCount -= 1;
        if (self.timeCount <= 1) {
            [self.codeTimer invalidate];
            self.codeTimer = nil;
            self.sendCodeBtn.enabled = YES;
            [self.sendCodeBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
        }
    });
}

@end
